package com.ruoyi.consult.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consult.domain.Consult;
import com.ruoyi.consult.service.IConsultService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 纳税咨询管理Controller
 * 
 * @author ruoyi
 * @date 2023-04-07
 */
@RestController
@RequestMapping("/consult/consult")
public class ConsultController extends BaseController
{
    @Autowired
    private IConsultService consultService;

    /**
     * 查询纳税咨询管理列表
     */
    @PreAuthorize("@ss.hasPermi('consult:consult:list')")
    @GetMapping("/list")
    public TableDataInfo list(Consult consult)
    {
        startPage();
        List<Consult> list = consultService.selectConsultList(consult);
        return getDataTable(list);
    }

    /**+
     * 导出纳税咨询管理列表
     */
    @PreAuthorize("@ss.hasPermi('consult:consult:export')")
    @Log(title = "纳税咨询管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Consult consult)
    {
        List<Consult> list = consultService.selectConsultList(consult);
        ExcelUtil<Consult> util = new ExcelUtil<Consult>(Consult.class);
        util.exportExcel(response, list, "纳税咨询管理数据");
    }

    /**
     * 获取纳税咨询管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('consult:consult:query')")
    @GetMapping(value = "/{consultId}")
    public AjaxResult getInfo(@PathVariable("consultId") Integer consultId)
    {
        return success(consultService.selectConsultByConsultId(consultId));
    }

    /**
     * 新增纳税咨询管理
     */
    @PreAuthorize("@ss.hasPermi('consult:consult:add')")
    @Log(title = "纳税咨询管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Consult consult)
    {
        return toAjax(consultService.insertConsult(consult));
    }

    /**
     * 修改纳税咨询管理
     */
    @PreAuthorize("@ss.hasPermi('consult:consult:edit')")
    @Log(title = "纳税咨询管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Consult consult)
    {
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
        String format = formatter.format(date);
        String s = format.substring(6, 10) + "-" + format.substring(3, 5) + "-" + format.substring(0, 2);
        System.out.println("拼接的时间是："+s);
        consult.setRecoveryTime(s);
        consult.setState(0);
        return toAjax(consultService.updateConsult(consult));
    }

    /**
     * 删除纳税咨询管理
     */
    @PreAuthorize("@ss.hasPermi('consult:consult:remove')")
    @Log(title = "纳税咨询管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{consultIds}")
    public AjaxResult remove(@PathVariable Integer[] consultIds)
    {
        return toAjax(consultService.deleteConsultByConsultIds(consultIds));
    }
}
